package com.bootcamp.javase.inner;

/**
 * @program: InnerCode
 * @description: define a geometry abstract class
 * @author: Keyu Li
 * @create: 2021-09-03 20:09
 **/

public class TestGeometry {
    public static void main(String[] args) {
        Rectangular rec = new Rectangular(12,20);
        Circle cl = new Circle(11.1);
        Square sq = new Square(3.3);

        rec.draw();
        System.out.println("长："+ rec.getLength()+ "，宽：" +rec.getWidth()
                + "，周长：" +rec.getPerimeter()+ "，面积：" +rec.getSize());
        cl.draw();
        System.out.println("半径："+cl.getRadius()
                +"，周长："+cl.getPerimeter()+"，面积："+cl.getSize());
        sq.draw();
        System.out.println("边长："+sq.getLength()
                +"，周长："+sq.getPerimeter()
                +"，面积："+sq.getSize());
    }
}

abstract class Geometry {
    private double perimeter;
    private double size;

    public Geometry(double perimeter, double size) {
        this.perimeter = perimeter;
        this.size = size;
    }

    public double getPerimeter(){
        return perimeter;
    }

    public double getSize(){
        return size;
    }

    abstract void draw();
}

class Rectangular extends Geometry {
    private double length;
    private double width;

    public double getLength() {
        return length;
    }

    public double getWidth() {
        return width;
    }

    public Rectangular(double length, double width) {
        super(2*(length+width),length * width);
        this.length = length;
        this.width = width;
    }

    @Override
    void draw() {
        System.out.println("画矩形！");
    }
}

class Circle extends Geometry {
    private double radius;
    private final static double PI = Math.PI;

    public double getRadius() {
        return radius;
    }

    public Circle(double radius) {
        super( 2 * PI * radius, PI * radius * radius);
        this.radius = radius;
    }

    @Override
    void draw() {
        System.out.println("画圆形！");
    }
}

class Square extends Geometry {
    private double length;

    public double getLength() {
        return length;
    }

    public Square(double length) {
        super(4 * length, length * length);
        this.length = length;
    }

    @Override
    void draw() {
        System.out.println("画正方形！");
    }
}